package com.ruoyi.eduadmin.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.eduadmin.domain.TTeachTrace;
import com.ruoyi.eduadmin.dto.AttentionDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.eduadmin.domain.TAttention;
import com.ruoyi.eduadmin.service.ITAttentionService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 关注列表Controller
 * 
 * @author hyk
 * @date 2022-12-26
 */
@RestController
@RequestMapping("/attention")
public class TAttentionController extends BaseController
{
    @Autowired
    private ITAttentionService tAttentionService;

    /**
     * 查询关注列表列表
     */
    @RequiresPermissions("eduadmin:attention:list")
    @GetMapping("/list")
    public TableDataInfo list(TAttention tAttention)
    {
        startPage();
        List<TAttention> list = tAttentionService.selectTAttentionList(tAttention);
        return getDataTable(list);
    }

    /**
     * 导出关注列表列表
     */
    @RequiresPermissions("eduadmin:attention:export")
    @Log(title = "关注列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TAttention tAttention)
    {
        List<TAttention> list = tAttentionService.selectTAttentionList(tAttention);
        ExcelUtil<TAttention> util = new ExcelUtil<TAttention>(TAttention.class);
        util.exportExcel(response, list, "关注列表数据");
    }

    /**
     * 获取关注列表详细信息
     */
    @RequiresPermissions("eduadmin:attention:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tAttentionService.selectTAttentionById(id));
    }

    /**
     * 新增关注列表
     */
    @RequiresPermissions("eduadmin:attention:add")
    @Log(title = "关注列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TAttention tAttention)
    {
        return toAjax(tAttentionService.insertTAttention(tAttention));
    }

    /**
     * 修改关注列表
     */
    @RequiresPermissions("eduadmin:attention:edit")
    @Log(title = "关注列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TAttention tAttention)
    {
        return toAjax(tAttentionService.updateTAttention(tAttention));
    }

    /**
     * 删除关注列表
     */
    @RequiresPermissions("eduadmin:attention:remove")
    @Log(title = "关注列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tAttentionService.deleteTAttentionByIds(ids));
    }

    /**
     * 根据学生id查询跟踪记录
     */
    @RequiresPermissions("eduadmin:attention:trace")
    @GetMapping("/trace/{id}")
    public List<TTeachTrace> trace(@PathVariable("id") Long id)
    {
        List<TTeachTrace> list = tAttentionService.selectTeacherTrace(id);
        return list;
    }

    /**
     * 根据班级获取关注列表
     */
    @GetMapping("/follow")
    public List<AttentionDto> getAttentionByClassName ()
    {
        List<AttentionDto> list = tAttentionService.getAttentionByClassName();
        return list;
    }

}
